package com.link.base.base.project.controller;

import com.link.base.base.project.model.Comptype;
import com.link.base.base.project.service.ComptypeService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.model.BasicModel;
import com.link.core.basic.query.QueryParams;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 零件类型
 *
 * @author 阳晓琳
 * @date 2020-09-24 18:03:43
 */
@Controller
@RequestMapping("/link/comptype")
public class ComptypeController extends BasicController<Comptype> {

    private static final Logger logger = LoggerFactory.getLogger(ComptypeController.class);

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private ComptypeService comptypeService;

    @Override
    public BasicService<Comptype> getBasicService() throws Exception {
        return comptypeService;
    }


    @RequestMapping({"/picklistPage"})
    @ResponseBody
    public Map<String, Object> picklistPage(@JsonParam QueryParams qps,
                                            @JsonParam Comptype entity,
                                            HttpSession session,
                                            HttpServletRequest request,
                                            HttpServletResponse response) {
        HashMap result = new HashMap(8);

        try {
            Comptype temp = BasicModel.transformClass(entity, qps);
            List<Comptype> list = comptypeService.picklistPage(temp);
            result.put("success", true);
            result.put("rows", list);
            this.pushCurrentDataCache(list, session.getId(), "base", false);
            result.put("total", getCount(temp, list.size()));
            result.put("code", "200");
        } catch (Exception var10) {
            logger.error("BasicController捕获异常: ", var10);
            result.put("success", false);
            result.put("rows", new ArrayList());
            result.put("result", var10.getMessage());
            result.put("code", "400");
        }
        return result;
    }
}
